package cup.modules.auth.utils;

import cn.hutool.core.util.RandomUtil;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * projectName:integrated
 * time:2022/2/21 22:17
 * description:
 */
public class PasswordUtil {
	//小写字母
    public final static List<String> word = Arrays.asList(
            "a", "b", "c", "d", "e", "f", "g",
            "h", "j", "k", "m", "n",
            "p", "q", "r", "s", "t",
            "u", "v", "w", "x", "y", "z");

	//数字
    public final static List<String> number = Arrays.asList(
            "1", "2", "3", "4", "5", "6", "7", "8", "9"
    );

	//大写
	public final static List<String> capital = Arrays.asList(
		"A", "B", "C", "D", "E", "F", "G",
		"H", "J", "K", "M", "N",
		"P", "Q", "R", "S", "T",
		"U", "V", "W", "X", "Y", "Z");

	//特殊符号
    public final static List<String> special = Arrays.asList(
            "~", "!", "@", "#", "$"
    );

    public static String randomPassword() {
        StringBuilder stringBuilder=new StringBuilder();
        int a = RandomUtil.randomInt(3, 4);
        int b = RandomUtil.randomInt(3, 4);
        int c = RandomUtil.randomInt(3, 4);
        int d = RandomUtil.randomInt(3, 4);

        List<String> strings = RandomUtil.randomEles(word, a);
        strings.addAll(RandomUtil.randomEles(number, b));
        strings.addAll(RandomUtil.randomEles(capital, c));
        strings.addAll(RandomUtil.randomEles(special, d));
		Collections.shuffle(strings);
        for (String s : strings) {
            stringBuilder.append(s);
        }
        return stringBuilder.toString();
    }

    public static void main(String[] args) throws Exception {
        System.out.println(randomPassword());
    }
}
